<template>
  <div>
    <!-- 搜索条件盒子 -->
    <div>
      <p class="pinformation">搜索条件</p>
      <el-form label-width="85px" ref="queryRef" :model="queryParams">
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同编号：" prop="contractCode">
              <el-input
                maxlength="100"
                clearable
                placeholder="请输入合同编号"
                v-model="queryParams.contractCode"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同类型：" prop="contractType">
              <el-select v-model="queryParams.contractType" placeholder="请选择合同类型" clearable @change="handleQuery">
                <el-option
                  v-for="dict in proxy.addListNoLimit(sys_contract_type)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同名称：" prop="contractName">
              <el-input
                maxlength="100"
                clearable
                placeholder="请输入合同名称"
                v-model="queryParams.contractName"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="紧急类型：" prop="degree">
              <el-select v-model="queryParams.degree" placeholder="请选择紧急类型" clearable @change="handleQuery">
                <el-option
                  v-for="dict in proxy.addListNoLimit(sys_degree)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="委托单位：" prop="wtCustomName">
              <el-input
                maxlength="100"
                clearable
                placeholder="请输入委托单位："
                v-model="queryParams.wtCustomName"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-row justify="end">
              <el-button type="success" @click="handleQuery">搜索</el-button>
              <el-button class="business resetBtn" @click="resetQuery">重置</el-button>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 检测类别列表盒子 -->
    <div>
      <el-row>
          <p class="pinformation">合同列表</p>
          <p class="totalStyle">共 {{ total }} 条数据</p>
      </el-row>
      <el-table
        ref="mainTableRef"
        :data="checkTable"
        :row-class-name="tableRowClass"
        @row-click="rowClick"
        v-loading="loading"
      >
        <el-table-column show-overflow-tooltip label="合同编号" align="center" prop="contractCode" width="120"/>
        <el-table-column show-overflow-tooltip label="委托单位" align="center" prop="wtCustomName" />
      </el-table>
      <pagination
            v-show="total > 0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
          />
    </div>
  </div>
</template>

<script setup>
import { listSchedu } from "@/api/contract/check";

const { proxy } = getCurrentInstance();
const { sys_degree } = proxy.useDict(
  "sys_degree"
);
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const total = ref(0);
const checkTable = ref([]);
const loading = ref(true);

const props = defineProps({
  isSchedu: {
    type: Number
  }
});
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    contractType: -1,
    degree: -1,
    isSchedu: props.isSchedu
  }
});

const { queryParams, form } = toRefs(data);

watch(()=>total.value,()=> {
  if (total.value) {
    heightParams.value = [{tableName: "main", bottomHeight: 74}]
  } else {
    heightParams.value = [{tableName: "main", bottomHeight: 21}]
  }
  getTableHeight()
})

const heightParams = ref([{ tableName: "main", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
})

onUpdated(() => {
  nextTick(function() {
    getTableHeight();
  });
});

onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

const emits = defineEmits(["getSeqId"]);

function getList() {
  loading.value = true;
    listSchedu(queryParams.value).then(res => {
    checkTable.value = res.rows;
    total.value = res.total;
    loading.value = false;
  });
}

function rowClick(row) {
  emits("getSeqId", row.contractId);
  heightBright.value = row.contractId
}

function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}
function resetQuery() {
  proxy.resetForm('queryRef')
  getList();
}

const heightBright = ref("")
function tableRowClass({ row }) {
  if (row) {
    if (row.contractId == heightBright.value) {
      return "current-row";
    }
    return "";
  }
}

// defineExpose({
//   resetQuery
// });

getList();
</script>